import { toSuccess, useEntityManager } from "@sker/core"
import { AutoTaskScript, AutoTaskScriptNotFound, AutoUser } from "@sker/entities"
import { useData } from "@sker/runtime"
import { z } from "zod"

export default async () => {
    const input = z.object({
        type: z.string(),
        current: z.string(),
        pageSize: z.string()
    });
    const body = input.parse(useData());
    const current = parseInt(body.current)
    const pageSize = parseInt(body.pageSize)

    const [list, count] = await useEntityManager(async m => {
        if (body.type === `1`) {
            return await m.findAndCount(AutoTaskScript, { order: { id: 'desc' }, take: pageSize, skip: (current - 1) * pageSize })
        } else {
            return await m.findAndCount(AutoTaskScriptNotFound, { order: { id: 'desc' }, take: pageSize, skip: (current - 1) * pageSize })
        }
    })
    return toSuccess(list, count)
}
